import React from 'react'

import { connect } from '../utils/connect'

import {
  addAction,
  incAction
} from '../store/actionCreators'

function Home(props) {
  return (
    <div>
      <h1>Home</h1>
      <h2>当前计数：{props.counter}</h2>
      <button onClick={() => props.increment()}>+1</button>
      <button onClick={() => props.addNumber(5)}>+5</button>
    </div>
  )


}

const mapStateToProps = state => {
  return {
    counter: state.counter
  }
}

const mapDispatchProps = dispatch => {
  return {
    increment() {
      console.log("???")
      dispatch(incAction())
    },
    addNumber(num) {
      dispatch(addAction(num))
    }
  }
}

export default connect(mapStateToProps, mapDispatchProps)(Home)
